package com.itheima.demo1inetadress;

import java.net.InetAddress;

public class inetadressDemo1
{
    public static void main(String[] args) {
        //通过InetAdress来获取本机ip对象和对方ip对象
        try {
            //获取本机ip对象
            InetAddress inet1 = InetAddress.getLocalHost();
            System.out.println(inet1);
            //获取本机名
            System.out.println(inet1.getHostName());
            //获取本机ip地址
            System.out.println(inet1.getHostAddress());
            //访问对方的ip对象（百度）
            InetAddress inet2 = InetAddress.getByName("www.baidu.com");
            //获取对方ip地址
            System.out.println(inet2.getHostAddress());
            //获取对方主机名
            System.out.println(inet2.getHostName());
            //判断对方是否可达 5s
            System.out.println(inet2.isReachable(5000));
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
